import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [{
      path: 'home',
      name: 'Home',
      component: () => import('@/views/home/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  {
    path: '/information',
    component: Layout,
    children: [
      {
        path: 'list',
        name: 'information',
        component: () => import('@/views/informag/list'),
        meta: { title: '通告', icon: 'form' }
      }
    ]
  },

  {
    path: '/assets',
    component: Layout,
    redirect: '/example/table',
    name: 'assets',
    meta: { title: '用户', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'list',
        name: 'Table',
        component: () => import('@/views/table/userList'),
        meta: { title: '用户列表', icon: 'table' }
      },
      {
        path: 'use',
        name: 'Table',
        component: () => import('@/views/table/userAdd'),
        meta: { title: '用户添加', icon: 'table' }
      }
    ]
  },

  {
    path: '/attendance',
    component: Layout,
    redirect: '/attendance',
    name: 'Attendance',
    meta: { title: '考勤', icon: 'form' },
    children: [
      {
        path: 'index',
        name: 'employeeAttendance',
        component: () => import('@/views/Attendance/index'),
        meta: { title: '员工考勤', icon: 'form' }
      },
      {
        path: 'index2',
        name: 'attendanceManage',
        component: () => import('@/views/Attendance/index2'),
        meta: { title: '考勤管理', icon: 'form' }
      }
    ]
  },

  {
    path: '/hr',
    component: Layout,
    redirect: '/department',
    name: 'HR',
    meta: { title: '人事', icon: 'el-icon-s-order' },
    children: [
      {
        path: '/department',
        name: 'Department',
        component: () => import('@/views/hr/department/index'),
        meta: { title: '组织', icon: 'el-icon-s-management' }
      },
      {
        path: '/recruit',
        name: 'Recruit',
        // 必须加上才能找到路径
        component: () => import('@/views/hr/recruit/index'),
        meta: { title: '招聘', icon: 'nested' },
        children: [
          {
            path: '/post',
            name: 'PostList',
            component: () => import('@/views/hr/recruit/post/index'),
            meta: { title: '岗位列表', icon: 'form' }
          },
          {
            path: '/resume',
            name: 'ResumeList',
            component: () => import('@/views/hr/recruit/resume/index'),
            meta: { title: '简历列表', icon: 'form' }
          },

          {
            path: '/interview',
            name: 'InterviewList',
            component: () => import('@/views/hr/recruit/interview/index'),
            meta: { title: '面试列表', icon: 'form' }
          }
        ]
      }
    ]
  },

  {
    path: '/approval',
    component: Layout,
    redirect: '/approval/list',
    name: 'approval',
    meta: { title: '审批', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'list',
        name: 'myApproval',
        component: () => import('@/views/approval/index'),
        meta: { title: '我的审批', icon: 'table' }
      }
    ]
  },
  {
    path: '/custom',
    component: Layout,
    redirect: '/custom/all',
    name: 'customForm',
    meta: { title: '自定义表单', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'all',
        name: 'all',
        component: () => import('@/views/customForm/all/index'),
        meta: { title: '所有模板', icon: 'table' }
      },
      {
        path: 'add',
        name: 'add',
        component: () => import('@/views/customForm/add/index'),
        meta: { title: '创建模板', icon: 'table' }
      },
      {
        path: 'outline',
        name: 'outline',
        component: () => import('@/views/customForm/detail/index'),
        meta: { title: '我的表单', icon: 'table' }
      }
    ]
  },
  {
    path: '/admin',
    component: Layout,
    redirect: '/admin/perm',
    name: 'rbac',
    meta: { title: '系统管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'perm',
        name: 'perm',
        component: () => import('@/views/admin/perm/index'),
        meta: { title: '权限管理', icon: 'table' },
        children: [
          {
            path: 'list',
            component: () => import('@/views/admin/perm/list'),
            name: 'permList',
            meta: { title: '权限列表' }
          },
          {
            path: 'add',
            component: () => import('@/views/admin/perm/add/index'),
            name: 'permAdd',
            meta: { title: '增加权限' }
          }
        ]
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/admin/role/index'),
        meta: { title: '角色管理', icon: 'table' },
        children: [
          {
            path: 'list',
            component: () => import('@/views/admin/role/list/index'),
            name: 'roleList',
            meta: { title: '角色列表' }
          },
          {
            path: 'add',
            component: () => import('@/views/admin/role/add/index'),
            name: 'roleAdd',
            meta: { title: '增加角色' }
          }
        ]
      },
      {
        path: 'menu',
        name: 'menu',
        component: () => import('@/views/admin/menu/index'),
        meta: { title: '菜单管理', icon: 'table' },
        children: [
          {
            path: 'list',
            component: () => import('@/views/admin/menu/list/index'),
            name: 'menuList',
            meta: { title: '菜单列表' }
          },
          {
            path: 'add',
            component: () => import('@/views/admin/menu/add/index'),
            name: 'menuAdd',
            meta: { title: '增加菜单' }
          }
        ]
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
